# @Time : 2024-10-23 11:24
# @Author : Fioman 
# @Phone : 13149920693
"""
查看变量占用字节数
"""
from sys import getsizeof

a = 10
print(getsizeof(a), getsizeof(int))  # 28 432 ,包含头部信息
b = True
print(getsizeof(b), getsizeof(bool))  # 28 432
c = 1.2
print(getsizeof(c), getsizeof(float))  # 24 432

s = "ABC"
print(getsizeof(s), getsizeof(str))  # 44 432
s = ""
print(getsizeof(s), getsizeof(str))  # 41 432

lst = []
print(getsizeof(lst), getsizeof(list))  # 56 432
lst.append(1)
print(getsizeof(lst), getsizeof(list))  # 88 432 # 一次性添加了 88 - 56 = 32 个字节的内存地址
lst.extend([1, 2, 3])
print(getsizeof(lst), getsizeof(list))  # 88 432

dt = dict()
print(getsizeof(dt), getsizeof(dict))  # 64 432
dt["A"] = 1
print(getsizeof(dt), getsizeof(dict))  # 184 432  # 一次性添加了 184 - 64 = 120 个字节的内存地址
